package com.momoauth.api_client.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.momoauth.api_client.entity.Login_Log;
import com.momoauth.api_client.mapper.LoginLogMapper;
import com.momoauth.common.core.result.ResponseResurt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/log")
@Api(tags = "日志")
public class LoginLogController {

    @Resource
    LoginLogMapper loginLogMapper;

    /**
     * 登录日志列表
     * @param login_log
     * @return
     */
    @ApiOperation(value = "登录日志列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页数", required = true)
    })
    @RequestMapping(value = "/getLoginLogList", method = RequestMethod.GET)
    public ResponseResurt getLoginLogList(Login_Log login_log) {
        QueryWrapper<Login_Log> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("logId"); //按主键倒序排序
        Page<Login_Log> page = new Page<>(login_log.getCurrentPage(),login_log.getPageSize());
        page.setRecords(loginLogMapper.getLoginLogList(page,queryWrapper));
        return ResponseResurt.success().data(page);
    }
}
